package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysPost;
import io.mybatis.example.springboot.service.SysPostService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_post - 岗位信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysPosts")
public class SysPostController {

  @Autowired
  private SysPostService sysPostService;

  @PostMapping
  public DataResponse<SysPostDO> save(@RequestBody SysPostDO sysPost) {
    return DataResponse.ok(sysPostService.save( sysPost));
  }

  @GetMapping
  public RowsResponse<SysPostDO> findList(@RequestBody SysPostDO sysPost) {
    return RowsResponse.ok(sysPostService.findList( sysPost));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysPostDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysPostService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysPostDO> update(@PathVariable("id") Long id, @RequestBody SysPostDO sysPost) {
    sysPost.setId(id);
    return DataResponse.ok(sysPostService.update( sysPost));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysPostService.deleteById(id) == 1);
  }

}
